<%@page import="cc.tongyuan.dcsystem.sys.domainmodel.PermissionGroupItemsModel"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ page language="java" import="cc.tongyuan.dcsystem.sys.domainmodel.*" %>
<%@ page language="java" import="cc.tongyuan.dcsystem.sys.domainmodel.enums.*" %>
<script type="text/javascript">
    var loading_img = "<%=request.getContextPath()%>/Content/images/loading_16x16.gif"; 
    function checkAll(chk, id) {
        if (id == undefined)
            $("input[type='checkbox']").each(function () { this.checked = chk.checked; });
        else {
            $("#" + id + " input[type='checkbox']").each(function () { this.checked = chk.checked; });
        }
    } 
</script>

<%
	for (PermissionGroupItemsDto groupItem : (List<PermissionGroupItemsDto>)request.getAttribute("permissionGroupItems") ){
%>
    <fieldset class="group">
        <legend class="group-title">
        	<input type="checkbox" name="CheckAll<%=groupItem.getGroup().getId()%>" onclick="checkAll(this, 'group-<%=groupItem.getGroup().getId()%>');" title = "全选/不选"/>
            <label name="CheckAll<%=groupItem.getGroup().getId()%>"><%=groupItem.getGroup().getName() %></label>
        </legend>
    
   <%
       	//CheckBox
          	  List<PermissionItemDto> checkBoxItems = groupItem.getItemsByDisplayStyle(PermissionItemDisplayStyle.CheckBox);
          	  if (checkBoxItems.size() > 0){
       %> 
            <div id="group-<%=groupItem.getGroup().getId()%>">
               <%
               	for (PermissionItemDto item : checkBoxItems){
                                  String displayName = item.getDisplayName();
               %>
                    <div class="checkbox-item" title="<%=displayName%>">
                    	<%
                    		if(request.getAttribute(item.getCode())!=null&&((String)request.getAttribute(item.getCode())).equalsIgnoreCase("true")){
                    	%>
                    	<input type="checkbox"  id="<%=item.getCode()%>" checked="checked" name="<%=item.getCode()%>" value="<%=item.getCode()%>"/>
                    	<%
                    		}else{
                    	%>
                    		<input type="checkbox"  id="<%=item.getCode()%>"  name="<%=item.getCode()%>"/>
                    	<%
                    		}
                    	%>
                    	<label name="<%=item.getCode()%>"><%=displayName%></label>
                    </div>
                <%
                	}
                %>
            </div>
    <%
    	}
          //TextBox 
          List<PermissionItemDto> textBoxItems = groupItem.getItemsByDisplayStyle(PermissionItemDisplayStyle.TextBox);
          if (textBoxItems.size() > 0){
    %>
           <div class="itemline">
           </div>
           <%
           	for (PermissionItemDto item : textBoxItems){
                          String displayName = item.getDisplayName();
           %>
            <div class="textbox-item" title="<%=displayName%>">
            	<%=displayName%> : <intput id="item.getCode()" name="item.getCode()"/>
            </div>
         <%
         	}
         %>
   <%
   	}
         //DropDownList
         List<PermissionItemDto> dropDownListItems = groupItem.getItemsByDisplayStyle(PermissionItemDisplayStyle.DropDownList);
         if (dropDownListItems.size() > 0){
   %>
           <div class="itemline">
           </div>
         <%
         	for (PermissionItemDto item : dropDownListItems){
                      String displayName = item.getDisplayName();
         %>
            <div class="dropdownlist-item" title="<%=displayName%>">
                <%=displayName%> : 
                <select name="<%=item.getCode()%>">
                	<option value="">=请选择=</option>
                </select>
            </div>
         <%
         	}
         %>
   <%
   	}
         //<!-- TreeView -->
         List<PermissionItemDto> treeViewItems = groupItem.getItemsByDisplayStyle(PermissionItemDisplayStyle.TreeView);
         if (treeViewItems.size() > 0){
   %>
           <div class="itemline">
           </div> 
        <%
         	for (PermissionItemDto item : treeViewItems){
         %>
            <div class="treeview-item">
                <div class="title" title="<%=item.getDisplayName()%>">
                	<input type="checkbox" name="CheckAll<%=item.getCode()%>" onclick="doCheckAllNodes(this, 'tree-view-<%=item.getCode()%>');" title = "全选/不选"/>
                	<label name="CheckAll<%=item.getCode()%>"><%=item.getDisplayName()%></label>
                	<input type="hidden" name="<%=item.getCode()%>"/>
                </div>
                <ul id="tree-view-<%=item.getCode()%>" class="treeview ztree">
                </ul>
            </div> 
        <%
         	}
         %>
    <%
    	}
    %>
    </fieldset>

     <!-- 初始化下拉框 -->
    <%
    	String dropDownListUrl ="/taskpro/api/GetDropDownListPermissionJsonData.do";
           for (PermissionItemDto item : dropDownListItems){
    %>

         <script type="text/javascript">
             initDropDownList('<%=item.getCode()%>', '<%=dropDownListUrl%>', '<%=groupItem.getGroup().getSystemId()%>', '<%=item.getId()%>', '${item.getCode()}');
         </script> 
    <%
     	}
            //初始化树视图
            String treeViewUrl ="/taskpro/api/GetTreeViewPermissionJsonData.do";
            for (PermissionItemDto item : treeViewItems){
     %>    

          <script type="text/javascript">
              initTreeView('tree-view-<%=item.getCode()%>', '<%=treeViewUrl%>', '<%=groupItem.getGroup().getSystemId()%>', '<%=item.getId()%>', '${item.getCode()}');
         </script>
    <%} %>
<%}%>